package com.ymatou.operate.trading.api.testcase;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.operate.trading.api.parameter.FrozenOrUnFrozenOrderBean;
import com.ymatou.operate.trading.api.service.FrozenOrUnFrozenOrderCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.database.sqlwapper.DefaultWapper;
/**
*订单投诉维权(冻结和解冻)接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_FrozenOrUnFrozenOrder{
	private static FrozenOrUnFrozenOrderBean frozenorunfrozenorderBean;
	private static FrozenOrUnFrozenOrderCall frozenorunfrozenorderCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("订单投诉维权(冻结和解冻)接口");
	}

	@Before
	public void caseUp() {
		frozenorunfrozenorderBean=new FrozenOrUnFrozenOrderBean();
		frozenorunfrozenorderCall=new FrozenOrUnFrozenOrderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(frozenorunfrozenorderCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_FrozenOrUnFrozenOrder_001() {
		Logger.start(true,"订单投诉维权冻结");
		try {
			// 创建订单
		    Logger.comment("前置数据准备");
		    PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

		    int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
		    int sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
		    int userId =placeOrderResp.getUserId();         
		    int tradingId = placeOrderResp.getTradingId();

		    BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
			// 买家付款
			 new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			 new OrderCallService().acceptOrder(orderId, sellerId);
	/*		// 商家发货
			 new OrderCallService().dispatched(orderId, sellerId);
		*/	
            Logger.comment("前置数据准备结束");
			frozenorunfrozenorderBean.setOrderId(orderId);
			frozenorunfrozenorderBean.setUserId(sellerId);
			frozenorunfrozenorderBean.setIsFrozen(true);
			frozenorunfrozenorderCall.setData(frozenorunfrozenorderBean);
			frozenorunfrozenorderCall.callService();						
			List<Map> list=new DefaultWapper().selectOrderFrozenByOrderId(orderId);
			Logger.verifyEquals("ok",frozenorunfrozenorderCall.getReturnData(),"验证接口返回状态");
			Logger.verifyEquals(true, (Boolean)list.get(0).get("bFrozen"), "验证Ymt_Order_Frozen 表 bFrozen");
			Logger.verifyIsContains("发起投诉", (String)list.get(0).get("sMemo"), "验证Ymt_Order_Frozen 表 sMemo");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_FrozenOrUnFrozenOrder_002() {
		Logger.start(true,"订单投诉维权解冻");
		try {
			// 创建订单
		    Logger.comment("前置数据准备");
		    PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

		    int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
		    int sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
		    int userId =placeOrderResp.getUserId();         
		    int tradingId = placeOrderResp.getTradingId();

		    BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
			// 买家付款
			 new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			 new OrderCallService().acceptOrder(orderId, sellerId);
	/*		// 商家发货
			 new OrderCallService().dispatched(orderId, sellerId);
		*/	
	        Logger.comment("前置数据准备结束");
			frozenorunfrozenorderBean.setOrderId(orderId);
			frozenorunfrozenorderBean.setUserId(sellerId);
			frozenorunfrozenorderBean.setIsFrozen(true);
			frozenorunfrozenorderCall.setData(frozenorunfrozenorderBean);
			frozenorunfrozenorderCall.callService();		
			//解冻
			frozenorunfrozenorderBean.setIsFrozen(false);
			Logger.comment("投诉解冻");
			frozenorunfrozenorderCall.setData(frozenorunfrozenorderBean);
			frozenorunfrozenorderCall.callService();		
			List<Map> list=new DefaultWapper().selectOrderFrozenByOrderId(orderId);
			Logger.verifyEquals("ok",frozenorunfrozenorderCall.getReturnData(),"验证接口返回状态");
			Logger.verifyEquals(false, (Boolean)list.get(0).get("bFrozen"), "验证Ymt_Order_Frozen 表 bFrozen");
			Logger.verifyIsContains("发起投诉", (String)list.get(0).get("sMemo"), "验证Ymt_Order_Frozen 表 sMemo");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
    @Category(P3.class)
    @TestCase
    public void Tc_FrozenOrUnFrozenOrder_003() {
        Logger.start(true,"订单号不存在");
        try {
            //frozenorunfrozenorderBean.setOrderId(orderId);
            frozenorunfrozenorderBean.setUserId(11111);
            frozenorunfrozenorderBean.setIsFrozen(true);
            frozenorunfrozenorderCall.setData(frozenorunfrozenorderBean);
            frozenorunfrozenorderCall.callService();        
            frozenorunfrozenorderCall.setData(frozenorunfrozenorderBean);
            frozenorunfrozenorderCall.callService();           
            Logger.verifyEquals("ok",frozenorunfrozenorderCall.getReturnData(),"验证接口返回状态");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
}